From c9b2f325abe3c3c0bbae483a91be44b7bdce5564 Mon Sep 17 00:00:00 2001 From: Jakob Haufe Date: Sun, 29 Oct 2017 13:32:44 +0100 Subject: [PATCH] Initial import --- Makefile | 34 ++++++++++++++++++++++++++++++++++ bcd2dec.h | 1 + bcd2dec.s | 21 +++++++++++++++++++++ binlog.h | 18 ++++++++++++++++++ crc16.h | 2 ++ crc16.pl | 8 ++++++++ crc16.s | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ crctest.c | 36 ++++++++++++++++++++++++++++++++++++ diskbench.c | 37 +++++++++++++++++++++++++++++++++++++ 9 files changed, 209 insertions(+) create mode 100644 Makefile create mode 100644 bcd2dec.h create mode 100644 bcd2dec.s create mode 100644 binlog.h create mode 100644 crc16.h create mode 100644 crc16.pl create mode 100644 crc16.s create mode 100644 crctest.c create mode 100644 diskbench.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..eac00d8 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +CC=cc65 +AS=ca65 +LD=cl65 + +CFLAGS= -t c128 + +all: image crctest + +image: diskbench.d71 + +diskbench.d71: diskbench + c1541 -format "diskbench",db d71 diskbench.d71 + touch data + c1541 -attach diskbench.d71 -write diskbench + c1541 -attach diskbench.d71 -write data data,s + +%.s: %.c + ${CC} ${CFLAGS} -O1 $< -o $@ + +%.o: %.s + ${AS} ${CFLAGS} $< -o $@ + +diskbench.s: diskbench.c + +diskbench: diskbench.o bcd2dec.o + ${LD} -t c128 $^ -o $@ + +crctest.s: crctest.c + +crctest: crctest.o crc16.o bcd2dec.o + ${LD} -Ln crctest.lbl -t c128 $^ -o $@ + +clean: + rm -f *.o crctest diskbench diskbench.d71 data *.lbl crctest.s diskbench.s diff --git a/bcd2dec.h b/bcd2dec.h new file mode 100644 index 0000000..f3fa98c --- /dev/null +++ b/bcd2dec.h @@ -0,0 +1 @@ +extern uint8_t __fastcall__ bcd2dec(uint8_t bcd); diff --git a/bcd2dec.s b/bcd2dec.s new file mode 100644 index 0000000..5ef08e2 --- /dev/null +++ b/bcd2dec.s @@ -0,0 +1,21 @@ + + .export _bcd2dec + .importzp tmp1,tmp2 + +.code + +.proc _bcd2dec + tax + and #%00001111 + sta tmp1 + txa + and #%11110000 ; *16 + lsr ; *8 + sta tmp2 + lsr + lsr ; *2 + adc tmp2 ; = *10 + adc tmp1 + ldx #0 + rts +.endproc diff --git a/binlog.h b/binlog.h new file mode 100644 index 0000000..1b656a3 --- /dev/null +++ b/binlog.h @@ -0,0 +1,18 @@ + +struct logentry { + uint32_t ts; //4 + enum trans_type tag; //1 + union { //4 + struct sale { //4 + uint8_t user; + uint8_t itemid; + int16_t amount; + }; + + struct credit { //3 + uint8_t user; + int16_t amount_cent; + }; + } + uint16_t crc; //2 +} diff --git a/crc16.h b/crc16.h new file mode 100644 index 0000000..04a8aa8 --- /dev/null +++ b/crc16.h @@ -0,0 +1,2 @@ +extern uint16_t __fastcall__ crc16_ccitt(uint16_t crc, uint8_t in); + diff --git a/crc16.pl b/crc16.pl new file mode 100644 index 0000000..5bf4384 --- /dev/null +++ b/crc16.pl @@ -0,0 +1,8 @@ +use Digest::CRC qw(crcccitt); +use Data::Dumper; + + +my $data = join("", map {chr $_} (1..16)); + +printf "%04X\n",crcccitt("$data"); + diff --git a/crc16.s b/crc16.s new file mode 100644 index 0000000..6e41402 --- /dev/null +++ b/crc16.s @@ -0,0 +1,52 @@ + + .export _crc16_ccitt + .importzp tmp1, tmp2, tmp3 + .import popax + +.code + +CRCLO := tmp1 +CRCHI := tmp2 + +;; Ad[ao]pted from http://6502.org/source/integers/crc-more.html (Greg Cook) + +;; uint16t __fastcall__ crc16_ccitt(uint16_t crc, uint8_t input) +.proc _crc16_ccitt + STA tmp3 + JSR popax + STA CRCLO + STX CRCHI + LDA tmp3 + + EOR CRCHI ; A contained the data + STA CRCHI ; XOR it into high byte + LSR ; right shift A 4 bits + LSR ; to make top of x^12 term + LSR ; ($1...) + LSR + TAX ; save it + ASL ; then make top of x^5 term + EOR CRCLO ; and XOR that with low byte + STA CRCLO ; and save + TXA ; restore partial term + EOR CRCHI ; and update high byte + STA CRCHI ; and save + ASL ; left shift three + ASL ; the rest of the terms + ASL ; have feedback from x^12 + TAX ; save bottom of x^12 + ASL ; left shift two more + ASL ; watch the carry flag + EOR CRCHI ; bottom of x^5 ($..2.) + TAY ; save high byte + TXA ; fetch temp value + ROL ; bottom of x^12, middle of x^5! + EOR CRCLO ; finally update low byte + ;STA CRCHI ; then swap high and low bytes + ;STY CRCLO + + TAX ; Store result in registers + TYA + + RTS +.endproc diff --git a/crctest.c b/crctest.c new file mode 100644 index 0000000..732b202 --- /dev/null +++ b/crctest.c @@ -0,0 +1,36 @@ + +#include +#include +#include + +#include "bcd2dec.h" +#include "crc16.h" + +#define BUFSZ 16 + +uint8_t buffer[BUFSZ] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; + +int main(void) +{ + uint16_t i=0; + uint16_t crc=0xFFFF; + uint8_t sec, tenth; + + videomode(VIDEOMODE_80x25); + fast(); + + __asm__("jsr initsystime"); + + for(i=0; i +#include +#include + +#include "bcd2dec.h" + +uint8_t buffer[256]; + +int main(void) +{ + int c,i; + + videomode(VIDEOMODE_80x25); + fast(); + + __asm__("jsr initsystime"); + + c = cbm_open((uint8_t)1, (uint8_t)8, (uint8_t)8, "data,s,a"); + cprintf("[%2d] open\r\n", bcd2dec(CIA1.tod_sec)); + if(c) + { + return 1; + } + for(i=0; i< 32; i++) + { + c = cbm_write((uint8_t)1, buffer, 256); + cprintf("[%2d] write\r\n", bcd2dec(CIA1.tod_sec)); + if(c != 256) + { + return 1; + } + } + cbm_close(1); + cprintf("[%2d] close\r\n",bcd2dec(CIA1.tod_sec)); + return 0; +} -- 2.39.5