CでOOP
CでOOPっぽくリングバッファを実装
/* RINGクラス */ typedef struct { WORD size; WORD len; WORD wtp; WORD rdp; BYTE *buf; } RING; /* 生成 */ RING* RingCreate(BYTE size) { RING *this; this = (RING *)malloc(sizeof(RING)); this->size = size; this->len = 0; this->wtp = 0; this->rdp = 0; BufAlloc(this->buf, this->size); return(this); } void BufAlloc(BYTE *p, WORD size) { (BYTE *p)malloc(size); } /* クリア */ void RingFree(RING* this) { free(this); } /* 読 */ BYTE RingRead(RING* this) { BYTE d; d = this->rdp++; if(this->rdp >= this->size) { this->rdp = 0; } this->len--; return(d); } /* 書 */ void RingWrite(RS* this, BYTE d) { BYTE d; d = this->wtp++; if(this->wtp >= this->size) { this->wtp = 0; } this->len++; } /* 電源投入時 */ rRing = RingCreate((BYTE)256); sRing = RingCreate((BYTE)256); /* SCI割り込み */ RingWrite(rRing, (BYTE)rd);
ビルドもなんもしてないけどこんな感じか。
チームではmalloc禁止なのだよね Boo
仕事でなくて自分で大掛かりなものを作りたい。
動くやつ。
H8で。
考えよう。
あとしつこくOS作りたい。