|
|
1.1 root 1: //
2: // nono
1.1.1.2 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
1.1.1.4 ! root 7: //
! 8: // メモリストリーム
! 9: //
! 10:
1.1 root 11: #pragma once
12:
13: #include "header.h"
14:
15: // ホストのメモリ領域に対するストリームクラスみたいなもの。
16: // データの受け渡しはホストエンディアンで、
17: // アクセスはビッグエンディアンになる。
18: class MemoryStreamBE
19: {
20: public:
21: // コンストラクタ
22: MemoryStreamBE() {
23: }
1.1.1.4 ! root 24: MemoryStreamBE(void *start_) {
! 25: Init(start_);
1.1 root 26: }
27: // デストラクタ不要
28:
1.1.1.4 ! root 29: // 開始ポインタを設定する
! 30: // 現在のポインタ位置は開始ポインタ位置になる
! 31: void Init(void *start_) {
! 32: start = (uint8 *)start_;
! 33: ptr = start;
! 34: }
! 35:
! 36: // 開始ポインタを取得する
! 37: void *GetStartPtr() const
! 38: {
! 39: return (void *)start;
! 40: }
! 41:
! 42: // バイトオフセットを設定する
! 43: void SetOffset(uint32 ofs)
! 44: {
! 45: ptr = start + ofs;
1.1 root 46: }
47:
1.1.1.4 ! root 48: // 現在のバイトオフセットを取得する
! 49: uint32 GetOffset() const
! 50: {
! 51: return (uint32)(ptr - start);
1.1 root 52: }
53:
54: // 1バイト読み込んでポインタを進める
55: uint32 Read8() {
1.1.1.3 root 56: uint32 data = *ptr++;
1.1 root 57: return data;
58: }
59: // BE で2バイト読み込んでポインタを進める
60: uint32 Read16() {
1.1.1.3 root 61: uint32 data;
62: data = Read8() << 8;
63: data |= Read8();
64: return data;
1.1 root 65: }
66: // BE で4バイト読み込んでポインタを進める
67: uint32 Read32() {
1.1.1.3 root 68: uint32 data;
69: data = Read16() << 16;
70: data |= Read16();
71: return data;
1.1 root 72: }
73:
74: // 1バイト書き込んでポインタを進める
75: void Write8(uint32 data) {
1.1.1.3 root 76: *ptr++ = data;
1.1 root 77: }
78: // BE で2バイト書き込んでポインタを進める
79: void Write16(uint32 data) {
1.1.1.3 root 80: Write8(data >> 8);
81: Write8(data & 0xff);
1.1 root 82: }
83: // BE で4バイト書き込んでポインタを進める
84: void Write32(uint32 data) {
1.1.1.3 root 85: Write16(data >> 16);
86: Write16(data & 0xffff);
1.1 root 87: }
88:
89: private:
1.1.1.3 root 90: uint8 *ptr {};
1.1.1.4 ! root 91: uint8 *start {};
1.1 root 92: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.