mirror of
https://github.com/tdinucci/6502-emulator.git
synced 2025-03-28 01:31:15 +00:00
Improved sample program
This commit is contained in:
parent
96b694c946
commit
fd260cc840
BIN
sample/a.o65
BIN
sample/a.o65
Binary file not shown.
@ -1,72 +0,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
|
||||
|
||||
|
||||
|
171
sample/draw.s
Normal file
171
sample/draw.s
Normal file
@ -0,0 +1,171 @@
|
||||
; simple program that paints cycling colours to the screen using the
|
||||
; keyboard curor keys
|
||||
;
|
||||
; The emulator loads programs at 0x600 so make sure to assemble with text segment at this address.
|
||||
; Compile with xa using command:
|
||||
; xa draw.s -v -bt 1536
|
||||
|
||||
; draw position
|
||||
ldx #$00
|
||||
stx $00 ; draw position low
|
||||
ldx #$e0
|
||||
stx $01 ; draw position high
|
||||
|
||||
; buffer for last key pressed
|
||||
key_addr = $f001
|
||||
|
||||
; address that holds the current colour to draw with
|
||||
draw_colour_addr = $10
|
||||
|
||||
left_key_code = $50
|
||||
right_key_code = $4f
|
||||
up_key_code = $52
|
||||
down_key_code = $51
|
||||
|
||||
; main program loop
|
||||
loop
|
||||
jsr read_key
|
||||
|
||||
; if we didn't read a key loop back round
|
||||
cmp #$0
|
||||
beq loop
|
||||
|
||||
cmp #left_key_code
|
||||
bne not_left
|
||||
jsr move_left
|
||||
jmp loop
|
||||
|
||||
not_left
|
||||
cmp #right_key_code
|
||||
bne not_right
|
||||
jsr move_right
|
||||
jmp loop
|
||||
|
||||
not_right
|
||||
cmp #up_key_code
|
||||
bne not_up
|
||||
jsr move_up
|
||||
jmp loop
|
||||
|
||||
not_up
|
||||
cmp #down_key_code
|
||||
bne loop
|
||||
jsr move_down
|
||||
jmp loop
|
||||
|
||||
jmp loop
|
||||
|
||||
read_key
|
||||
lda key_addr
|
||||
|
||||
; clear the key press buffer so we don't read same key press twice
|
||||
ldx #$0
|
||||
stx key_addr
|
||||
|
||||
rts
|
||||
|
||||
move_right
|
||||
lda $00
|
||||
|
||||
; if we're at $ff then we need to increment the high byte before rendering
|
||||
cmp #$ff
|
||||
bne do_right_render
|
||||
|
||||
; if we're at $efff then we have to stop because we'd start writing outside of video memory
|
||||
lda $01
|
||||
cmp $ef
|
||||
bcs after_right_render
|
||||
|
||||
; increment high byte and reset the low one
|
||||
inc $01
|
||||
ldx #$00
|
||||
stx $00
|
||||
|
||||
do_right_render
|
||||
inc $00
|
||||
jsr render_dot
|
||||
|
||||
after_right_render
|
||||
rts
|
||||
|
||||
; comments for "move_right" also apply here but direction is obviously reversed
|
||||
move_left
|
||||
lda $00
|
||||
|
||||
cmp #$00
|
||||
bne do_left_render
|
||||
|
||||
lda $01
|
||||
cmp #$e0
|
||||
beq after_left_render
|
||||
|
||||
dec $01
|
||||
ldx #$00
|
||||
stx $00
|
||||
|
||||
do_left_render
|
||||
dec $00
|
||||
jsr render_dot
|
||||
|
||||
after_left_render
|
||||
rts
|
||||
|
||||
move_up
|
||||
; don't want to risk moving into non graphics memory so perform boundary checks
|
||||
ldx $00
|
||||
|
||||
; each line contains $40 (64) pixels, if low byte is above this then we're safe to move
|
||||
cpx #$40
|
||||
bcs after_up_boundary_check
|
||||
|
||||
; couldn't tell if we're safe by looking at low byte, does the high byte allow move?
|
||||
ldx $01
|
||||
cpx #$e0
|
||||
beq after_up_render
|
||||
|
||||
after_up_boundary_check
|
||||
lda $00
|
||||
sbc #$40
|
||||
sta $00
|
||||
; if carry flag is set then we'll also have to decrement the high byte
|
||||
bcs after_up_subtract
|
||||
dec $01
|
||||
|
||||
after_up_subtract
|
||||
jsr render_dot
|
||||
|
||||
after_up_render
|
||||
rts
|
||||
|
||||
; comments for "move_up" also apply here but direction is obviously reversed
|
||||
move_down
|
||||
ldx $00
|
||||
cpx #$9b
|
||||
bcc after_down_boundary_check
|
||||
ldx $01
|
||||
cpx #$ef
|
||||
beq after_down_render
|
||||
|
||||
after_down_boundary_check
|
||||
lda $00
|
||||
adc #$40
|
||||
sta $00
|
||||
bcc after_down_add
|
||||
inc $01
|
||||
|
||||
after_down_add
|
||||
jsr render_dot
|
||||
|
||||
after_down_render
|
||||
rts
|
||||
|
||||
render_dot
|
||||
; change the drawing colour (256 colours and we'll wrap around when $ff is hit)
|
||||
inc draw_colour_addr
|
||||
lda draw_colour_addr
|
||||
|
||||
; write the "draw colour" to address pointed to across ($01 $00) - little endian
|
||||
ldx #$00
|
||||
sta ($00, x)
|
||||
|
||||
rts
|
@ -1,76 +0,0 @@
|
||||
draw_addr = $e000
|
||||
key_addr = $f001
|
||||
draw_colour_addr = $10
|
||||
|
||||
loop
|
||||
lda #$0
|
||||
jsr read_key
|
||||
cmp #$0
|
||||
beq loop
|
||||
|
||||
cmp #$50
|
||||
bne not_left
|
||||
jsr move_left
|
||||
clv
|
||||
bvc loop
|
||||
|
||||
not_left
|
||||
cmp #$4f
|
||||
bne not_right
|
||||
jsr move_right
|
||||
clv
|
||||
bvc loop
|
||||
|
||||
not_right
|
||||
cmp #$52
|
||||
bne not_up
|
||||
jsr move_up
|
||||
clv
|
||||
bvc loop
|
||||
|
||||
not_up
|
||||
cmp #$51
|
||||
bne loop
|
||||
jsr move_down
|
||||
clv
|
||||
bvc loop
|
||||
|
||||
clv
|
||||
bvc loop
|
||||
|
||||
read_key
|
||||
lda key_addr
|
||||
ldx #$0
|
||||
stx key_addr
|
||||
rts
|
||||
|
||||
move_right
|
||||
inc $00
|
||||
jsr render_dot
|
||||
rts
|
||||
|
||||
move_left
|
||||
dec $00
|
||||
jsr render_dot
|
||||
rts
|
||||
|
||||
move_up
|
||||
lda $00
|
||||
sbc #$40
|
||||
sta $0
|
||||
jsr render_dot
|
||||
rts
|
||||
|
||||
move_down
|
||||
lda $00
|
||||
adc #$3f
|
||||
sta $0
|
||||
jsr render_dot
|
||||
rts
|
||||
|
||||
render_dot
|
||||
inc draw_colour_addr
|
||||
lda draw_colour_addr
|
||||
ldx $00
|
||||
sta draw_addr, x
|
||||
rts
|
@ -1,6 +1,5 @@
|
||||
#include "keyboard.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -14,28 +13,11 @@ namespace emu_6502 {
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
|
||||
//if(event.key.keysym.scancode < 255)
|
||||
if (event.key.keysym.scancode < 255)
|
||||
memory.set_at(LAST_KEY_PRESS_ADDR, event.key.keysym.scancode);
|
||||
|
||||
cout << "CODE: " << event.key.keysym.scancode << endl;
|
||||
// switch (event.key.keysym.sym) {
|
||||
// case SDLK_LEFT:
|
||||
// cout << "LEFT " << (uint16_t) count++ << endl;
|
||||
// break;
|
||||
// case SDLK_RIGHT:
|
||||
// cout << "RIGHT" << (uint16_t) count++ << endl;
|
||||
// break;
|
||||
// case SDLK_UP:
|
||||
// cout << "UP" << (uint16_t) count++ << endl;
|
||||
// break;
|
||||
// case SDLK_DOWN:
|
||||
// cout << "DOWN" << (uint16_t) count++ << endl;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace emu_6502 {
|
||||
draw_pixel(x, y, colour);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_Delay(50);
|
||||
SDL_Delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,8 +46,6 @@ namespace emu_6502 {
|
||||
green = (colour >> 2) & 0x07;
|
||||
blue = colour & 0x03;
|
||||
|
||||
//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, 255);
|
||||
SDL_Rect rect{};
|
||||
rect.x = x * PIXEL_WEIGHT;
|
||||
|
@ -62,5 +62,5 @@ TEST(LoadOpcodeHandlerContainer, RTS) {
|
||||
}
|
||||
|
||||
ASSERT_EQ(0x99, machine->get_cpu().get_a().get_value());
|
||||
ASSERT_EQ(0x605, machine->get_cpu().get_pc().get_value());
|
||||
ASSERT_EQ(0x604, machine->get_cpu().get_pc().get_value());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user