mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-25 14:42:16 +11:00
Move the CRC8 code into utility
This commit is contained in:
parent
491a37b938
commit
0f34399cca
4 changed files with 17 additions and 45 deletions
2
Makefile
2
Makefile
|
|
@ -16,7 +16,7 @@ GAME_PRG=game
|
|||
LIBS=clib-6502.a
|
||||
|
||||
MASTER_ASM_SRCS = tk2k_startup_master.s disk2.s master_func.s
|
||||
MASTER_C_SRCS = master_main.c dos_floppy.c
|
||||
MASTER_C_SRCS = master_main.c dos_floppy.c utility.c
|
||||
|
||||
INTRO_ASM_SRCS = tk2k_startup_module.s preserve_zero_pages.s
|
||||
INTRO_C_SRCS = intro_main.c utility.c
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ static uint16_t file_load_address[FILE_LIST_LEN] = { // This will hold the load
|
|||
static void init(void);
|
||||
static void init_floppy_data(uint8_t *cur_trk, uint8_t *cur_file);
|
||||
static uint8_t fill_trksec_list(uint8_t* cur_trk);
|
||||
static uint8_t calculate_crc8(uint8_t* data, uint8_t len);
|
||||
|
||||
// Low level initialization
|
||||
static void init(void) {
|
||||
|
|
@ -117,26 +116,6 @@ static void init_floppy_data(uint8_t *cur_trk, uint8_t *cur_file) {
|
|||
if (!initialized_correctly) __asm volatile(" brk\n":::);
|
||||
}
|
||||
|
||||
#define CRC8RDALLAS_POLY 0x31
|
||||
static uint8_t calculate_crc8(uint8_t* data, uint8_t len) {
|
||||
uint8_t crc = 0;
|
||||
|
||||
for(uint8_t data_idx = 0; data_idx < len; data_idx++) {
|
||||
uint8_t carry;
|
||||
uint8_t d = data[data_idx];
|
||||
|
||||
for (uint8_t i = 8; i > 0; i--) {
|
||||
carry = (crc & 0x80);
|
||||
crc <<= 1;
|
||||
if (d & 1) crc |= 1;
|
||||
d >>= 1;
|
||||
if (carry) crc ^= CRC8RDALLAS_POLY;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
__task int main(void) {
|
||||
uint8_t cur_trk = 0;
|
||||
uint8_t cur_file = 0;
|
||||
|
|
|
|||
|
|
@ -44,29 +44,22 @@ uint16_t lfsr_update(void) {
|
|||
return *lfsr;
|
||||
}
|
||||
|
||||
/*
|
||||
void print_line(const char* line, uint8_t off_x, uint8_t off_y) {
|
||||
POKEZ(ZP_CV, off_y);
|
||||
|
||||
uint8_t cur_ch;
|
||||
for(cur_ch = 0; line[cur_ch]; cur_ch++) {
|
||||
SETNORM();
|
||||
POKEZ(ZP_CH, cur_ch + off_x);
|
||||
#define CRC8RDALLAS_POLY 0x31
|
||||
uint8_t calculate_crc8(uint8_t* data, uint8_t len) {
|
||||
uint8_t crc = 0;
|
||||
|
||||
for(uint8_t data_idx = 0; data_idx < len; data_idx++) {
|
||||
uint8_t carry;
|
||||
uint8_t d = data[data_idx];
|
||||
|
||||
COUT1(line[cur_ch]|0x80);
|
||||
|
||||
SETINV();
|
||||
COUT1(' '|0x80);
|
||||
|
||||
for(uint8_t snd_loop = 0x70; snd_loop; snd_loop--) PEEK(IO_SPEAKER);
|
||||
|
||||
WAIT(0xBE);
|
||||
for (uint8_t i = 8; i > 0; i--) {
|
||||
carry = (crc & 0x80);
|
||||
crc <<= 1;
|
||||
if (d & 1) crc |= 1;
|
||||
d >>= 1;
|
||||
if (carry) crc ^= CRC8RDALLAS_POLY;
|
||||
}
|
||||
}
|
||||
|
||||
SETNORM();
|
||||
POKEZ(ZP_CH, cur_ch + off_x);
|
||||
|
||||
COUT1(' '|0x80);
|
||||
WAIT(0xFF);
|
||||
return crc;
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,6 +29,6 @@ uint8_t bit_reverse(uint8_t b);
|
|||
uint8_t bit_count(uint8_t b);
|
||||
void lfsr_init(uint16_t reg);
|
||||
uint16_t lfsr_update(void);
|
||||
//void print_line(const char* line, uint8_t off_x, uint8_t off_y);
|
||||
uint8_t calculate_crc8(uint8_t* data, uint8_t len);
|
||||
|
||||
#endif /* _UTILITY_HEADER_ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue