joy: button interface improved

This commit is contained in:
cr0sd 2020-03-03 17:55:11 -06:00
parent 3fe025b477
commit 23c3948959
7 changed files with 74 additions and 46 deletions

16
cpu.c
View File

@ -172,14 +172,14 @@ void cpu_exec(cpu_t*cpu,ram_t*ram)
// Bitwise ---
// AND
case 0x29: and( fetch() ); incpc(); break;
case 0x25: and( deref( fetch() ) ); incpc(); break;
case 0x35: and( deref( fetch() + cpu->x ) ); incpc(); break;
case 0x2D: and( deref( fetch16() ) ); incpc(); break;
case 0x3D: and( deref( fetch16() + cpu->x ) ); incpc(); break;
case 0x39: and( deref( fetch16() + cpu->y ) ); incpc(); break;
case 0x21: and( deref( deref( fetch() + cpu->x ) ) ); incpc(); break;
case 0x31: and( deref( deref( fetch() + cpu->y ) ) ); incpc(); break;
case 0x29: and( fetch() ); sr_nz(cpu->a); incpc(); break;
case 0x25: and( deref( fetch() ) ); sr_nz(cpu->a); incpc(); break;
case 0x35: and( deref( fetch() + cpu->x ) ); sr_nz(cpu->a); incpc(); break;
case 0x2D: and( deref( fetch16() ) ); sr_nz(cpu->x); incpc(); break;
case 0x3D: and( deref( fetch16() + cpu->x ) ); sr_nz(cpu->a); incpc(); break;
case 0x39: and( deref( fetch16() + cpu->y ) ); sr_nz(cpu->a); incpc(); break;
case 0x21: and( deref( deref( fetch() + cpu->x ) ) ); sr_nz(cpu->a); incpc(); break;
case 0x31: and( deref( deref( fetch() + cpu->y ) ) ); sr_nz(cpu->a); incpc(); break;
// EOR
// TODO Check if accumulator is changed, or memory

17
joy.c
View File

@ -50,17 +50,18 @@ void*joy_thread_update(void*d)
if(*b=='\033')
{
read(1,b,2);
if(b[1]=='A') joy->buttons.bits.up=1;//x=K_UP;
else if(b[1]=='B') joy->buttons.bits.down=1;//x=K_DOWN;
else if(b[1]=='D') joy->buttons.bits.right=1;//x=K_RIGHT;
else if(b[1]=='C') joy->buttons.bits.left=1;//x=K_LEFT;
if(b[1]=='A') joy->buttons.reg=0x1; //joy->buttons.bits.up=1;//x=K_UP;
else if(b[1]=='B') joy->buttons.reg=0x2; //joy->buttons.bits.down=1;//x=K_DOWN;
else if(b[1]=='D') joy->buttons.reg=0x4; //joy->buttons.bits.right=1;//x=K_RIGHT;
else if(b[1]=='C') joy->buttons.reg=0x8; //joy->buttons.bits.left=1;//x=K_LEFT;
//else
//x=0;
}
else if(*b==JOY_A) joy->buttons.bits.a=1;
else if(*b==JOY_B) joy->buttons.bits.b=1;
else if(*b==JOY_X) joy->buttons.bits.x=1;
else if(*b==JOY_Y) joy->buttons.bits.y=1;
else if(*b==JOY_A) joy->buttons.reg=0x10; //joy->buttons.bits.a=1;
else if(*b==JOY_B) joy->buttons.reg=0x20; //joy->buttons.bits.b=1;
else if(*b==JOY_X) joy->buttons.reg=0x40; //joy->buttons.bits.x=1;
else if(*b==JOY_Y) joy->buttons.reg=0x80; //joy->buttons.bits.y=1;
else joy->buttons.reg=0;
pthread_mutex_unlock(&(joy->mut));
}

View File

@ -19,6 +19,9 @@ checks:
@-$(CCAS65) -C 6502 -b 8000-10000 -o $*.o65 $*.s
@cat ines_header $*.o65 > $*.nes
@$(RM) $*.o65 $*.s
.c65.a65:
@echo "CC65 $*.a65"
@$(CC65) $*.c65 -o $*.a65
clean:
@echo "RM $(OBJS)"
@$(RM) $(OBJS)

View File

@ -1,12 +1,17 @@
int getone(void)
{
int y=99;
return y+5;
}
#define JOYP 0x6000
#define RAM(x) ((char*)0)[x]
void drawstuff(char*);
void main(void)
{
int x=0;
if(getone())
x=5;
drawstuff("hello there");
while(1);
}
void drawstuff(char*str)
{
int i=0;
for(i=0;str[i];++i)
RAM(JOYP)=str[i];
}

View File

@ -12,15 +12,10 @@ main:
ldx #$ff
txs
loop:
lda JOYP
lda #$f9
sta $01
and #1
cmp #1
bne loop
end:
lda #0
sta JOYP
jmp end
jmp *
.)

View File

@ -19,15 +19,9 @@ main:
; main loop
loop:
jsr drawbg
jsr drawme
jsr moveme
jsr wait
; clear player pos
ldx me
lda #0
sta VRAM,x
jsr drawme
;jsr wait
jmp loop
.)
@ -101,19 +95,46 @@ moveme:
; check keyboard input
lda JOYP
and #$02
cmp #$02
beq down
and #$01
bne up
lda JOYP
and #$02
bne down
lda JOYP
and #$04
bne left
lda JOYP
and #$08
bne right
jmp end
up:
lda me
sbc #30
sta me
jmp end
down:
lda me
adc #30
sta me
jmp end
lda #0
sta JOYP
left:
lda me
sbc #1
sta me
jmp end
right:
lda me
adc #1
sta me
jmp end
end:
rts

3
vis.c
View File

@ -2,6 +2,7 @@
#include"65.h"
#include"vis.h"
// Display information stored in VRAM
int vis_display(cpu_t*cpu,ram_t*ram)
{
int w=VIS_WIDTH;
@ -11,6 +12,8 @@ int vis_display(cpu_t*cpu,ram_t*ram)
{
int b=ram->ram[VRAM+i];
move(i/w,i%w);
clrtoeol();
if(b==0xff)
addch(b?(ACS_CKBOARD):(' '));
else if(b==0x21)