M .build.yml => .build.yml +6 -1
@@ 12,11 12,16 @@ tasks:
cd 6502
mkdir build
cd build
- cmake ..
+ cmake .. -DCMAKE_BUILD_TYPE=Release
- build: |
cd 6502/build
make -j
./6502 -h
+ - pack: |
+ cd 6502/build
+ cpack
+ dpkg -I 6502.deb
artifacts:
- 6502/build/6502
- 6502/build/as/6502-as
+ - 6502/build/6502.deb
M CMakeLists.txt => CMakeLists.txt +15 -0
@@ 26,6 26,21 @@ if (${GEN_INSTRUCTIONS_HEADER})
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif()
+find_library(readline SDL2 GL GLU GLEW m rt pthread)
+
add_executable(6502 main.c cpu.c cpu.h dbg.c dbg.h
instructions.h gui.h gui.c screen.h screen.c common.h common.c)
target_link_libraries(6502 readline SDL2 GL GLU GLEW m rt pthread)
+
+install(TARGETS 6502)
+
+set(CPACK_GENERATOR "DEB")
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "swissChili")
+set(CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl2-dev, libreadline-dev, libglew-dev")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "6502 emulator, debugger, and assembler")
+set(CPACK_PACKAGE_VERSION_MAJOR 0)
+set(CPACK_PACKAGE_VERSION_MINOR 1)
+set(CPACK_PACKAGE_VERSION_PATCH 0)
+set(CPACK_PACKAGE_FILE_NAME "6502")
+
+include(CPack)
M as/CMakeLists.txt => as/CMakeLists.txt +2 -0
@@ 14,3 14,5 @@ endif()
add_executable(6502-as main.c as.h as.c map.h map.c hash.c hash.c)
+
+install(TARGETS 6502-as)
M as/as.c => as/as.c +6 -4
@@ 21,6 21,7 @@ enum
};
#define ERR "\033[31m"
+#define GREEN "\033[32m"
#define RESET "\033[0m"
#define MAX_LEN (0xFFFF - 0x600)
#define MAX_INSTS (MAX_LEN / 2)
@@ 534,7 535,8 @@ uint32_t assemble(char *code, FILE *out)
if ((no_argument && (_mn == AM_IMP || _mn == AM_ACC)) \
|| (mnemonic == _mn && parse_arg(line, am, arg))) \
{ \
- printf("AM_ succeeded: %s\n", #am); \
+ printf(GREEN "AM_ succeeded: %s at pc=$%x\n" RESET, \
+ #am, pc); \
arg->opcode = op; \
pc += len; \
print_inst(arg); \
@@ 599,21 601,21 @@ uint32_t assemble(char *code, FILE *out)
}
curr_pc += 2;
int16_t diff = lbl - curr_pc;
- printf("ARG_REL, pc (after) == %x, diff = %d\n", curr_pc, diff);
+ printf("ARG_REL, pc (after) == %x, diff = %hx\n", curr_pc, (uint8_t) diff);
if ((diff < 0 ? -diff : diff) > 0xFF)
{
printf(ERR "Error on line %d: label '%s' is too far away for a relative jump" RESET "\n", insts[i]->line, insts[i]->label);
printf("pc == %hx, label is at %hx\n", curr_pc, lbl);
goto cleanup;
}
- putshort((uint8_t) diff, out);
+ putc((uint8_t) diff, out);
break;
}
default:
curr_pc++;
}
}
-
+
cleanup:
printf("-----\n");
printf("At end, there are %d instructions\n", num_insts);
A as/test/disco.s => as/test/disco.s +22 -0
@@ 0,0 1,22 @@
+; Taken from 6502asm.com
+
+
+start:
+ inx ; 600
+ txa ; 601
+ sta $200, y ; 602
+ sta $300, y ; 605
+ sta $400, y ; 608
+ sta $500, y ; 60b
+ iny ; 60e
+ tya ; 60f
+ cmp 16 ; 610
+ bne do ; 612
+ iny ; 614
+ jmp start ; 615
+do:
+ iny ; 618
+ iny ; 619
+ iny ; 61a
+ iny ; 61b
+ jmp start ; 61c
M cpu.c => cpu.c +8 -6
@@ 40,20 40,22 @@ cpu_t new_cpu()
uint16_t le_to_native(uint8_t a, uint8_t b)
{
#ifdef LITTLE_ENDIAN
+ //printf("Little Endian\n");
return b << 8 | a;
#else
- return le16toh(a << 8 | b);
+ //printf("Big Endian\n");
+ return a << 8 | b;
#endif
}
void native_to_le(uint16_t n, uint8_t *a, uint8_t *b)
{
#ifdef LITTLE_ENDIAN
- *a = n >> 8;
- *b = n & 0xFF;
-#else
- *a = n & 0xFF;
*b = n >> 8;
+ *a = n & 0xFF;
+#else
+ *b = n & 0xFF;
+ *a = n >> 8;
#endif
}
@@ 80,7 82,7 @@ uint16_t stack_pople(cpu_t *cpu)
{
uint8_t a = stack_pop(cpu);
uint8_t b = stack_pop(cpu);
- return le_to_native(a, b);
+ return le_to_native(b, a);
}
void free_cpu(cpu_t *cpu)
M disco.dat => disco.dat +0 -0