nibble_table: validating qkumba's DOS read nibble generation code

This commit is contained in:
Vince Weaver 2018-10-12 17:10:31 -04:00
parent 6e6c7e6c2a
commit bb4a67e9d2
4 changed files with 159 additions and 2 deletions

View File

@ -207,9 +207,9 @@ void lsr(void) {
c=temp_a&0x1;
temp_a=temp_a>>1;
a=(temp_a&0xff);
a=(temp_a&0x7f); // always shift 0 into top
z=(a==0);
n=!!(a&0x80);
n=!!(a&0x80); // can this ever be 1? no?
// printf("LSR A=%x\n",a);
}
@ -362,6 +362,21 @@ void bit(int value) {
}
/* a is not modified */
void bit_mem(int addr) {
int temp_a;
temp_a=a&ram[addr];
temp_a&=0xff;
z=(temp_a==0);
n=(ram[addr]&0x80);
v=(ram[addr]&0x40);
}
void lda(int addr) {
a=ram[addr];
@ -441,6 +456,62 @@ void eor(int value) {
}
void ora(int value) {
int temp_a;
int temp_value;
int result;
temp_a=a&0xff;
temp_value=value&0xff;
result=(temp_a|temp_value);
n=(result&0x80)>>7;
a=result&0xff;
z=(a==0);
}
void ora_mem(int addr) {
int temp_a;
int temp_value;
int result;
temp_a=a&0xff;
temp_value=ram[addr]&0xff;
result=(temp_a|temp_value);
n=(result&0x80)>>7;
a=result&0xff;
z=(a==0);
}
void and(int value) {
int temp_a;
int temp_value;
int result;
temp_a=a&0xff;
temp_value=value&0xff;
result=(temp_a&temp_value);
n=(result&0x80)>>7;
a=result&0xff;
z=(a==0);
}
unsigned char high(int value) {
return (value>>8)&0xff;
}

View File

@ -8,7 +8,12 @@ unsigned short y_indirect(unsigned char base, unsigned char y);
int init_6502(void);
void adc(int value);
void sbc(int value);
void and(int value);
void and_mem(int addr);
void ora(int value);
void ora_mem(int addr);
void eor(int value);
void eor_mem(int addr);
void cmp(int value);
void cpy(int value);
void cpx(int value);

31
gr-sim/dos/Makefile Normal file
View File

@ -0,0 +1,31 @@
CC = gcc
CFLAGS = -Wall -O2 -I.. -g
LFLAGS = -lm
SDL_LIBS= `sdl-config --libs`
SDL_INCLUDE= `sdl-config --cflags`
GR_SIM = ../gr-sim.a
all: nibble
####
nibble: nibble.o $(GR_SIM)
$(CC) $(LFLAGS) $(SDL_LIBS) -o nibble nibble.o $(GR_SIM)
nibble.o: nibble.c
$(CC) $(CFLAGS) -c nibble.c
####
nibble2: nibble2.o $(GR_SIM)
$(CC) $(LFLAGS) $(SDL_LIBS) -o nibble2 nibble2.o $(GR_SIM)
nibble2.o: nibble2.c
$(CC) $(CFLAGS) -c nibble2.c
####
clean:
rm -f *~ *.o nibble nibble2

50
gr-sim/dos/nibble.c Normal file
View File

@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include "gr-sim.h"
#include "tfv_utils.h"
#include "tfv_zp.h"
#include "6502_emulate.h"
int main(int argc, char **argv) {
int yy;
grsim_init();
gr();
yy=0;
printf("****yy=%d\n",yy);
y=yy; // ldy #0
x=3; // ldx #3
L1:
ram[0x3c]=x; // stx $3c
a=x; // txa
asl(); // asl
bit_mem(0x3c); // bit $3c
if (z==1) goto L3; // beq L3
ora_mem(0x3c); // ora $3c
eor(0xff); // eor #$ff
and(0x7e); // and #$7e
L2:
if (c==1) goto L3; // bcs L3
lsr(); // lsr
if (z==0) goto L2; // bne L2
a=y; // tya
printf("%x=%x\n",x,a); // sta nibtbl, x
y++; // iny
L3:
x++; // inx
if (!(x&0x80)) goto L1; // bpl L1
return 0;
}