Add FloppyDisk class to start consolidating disk image decoding

This commit is contained in:
Jordan Goulder 2025-01-14 17:44:59 -05:00
parent 6d79a35ce5
commit e6bdde292d
2 changed files with 19 additions and 6 deletions

View File

@ -1,18 +1,18 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { decodeBootSector } from '@/floppy/disk.ts'
import { FloppyDisk } from '@/floppy/disk.ts'
const { data = new ArrayBuffer(0) } = defineProps<{ data: ArrayBuffer }>()
const bootSector = computed(() => {
return decodeBootSector(data)
const floppyDisk = computed(() => {
return new FloppyDisk(data)
})
</script>
<template>
<section v-if="bootSector">
<section v-if="floppyDisk.bootSectorInfo">
<h3>Boot Sector</h3>
<pre>{{ bootSector }}</pre>
<pre>{{ floppyDisk.bootSectorInfo }}</pre>
</section>
</template>

View File

@ -30,7 +30,20 @@ export interface IBiosParameterBlock {
totalSectorsLarge: number
}
export function decodeBootSector(buffer: ArrayBuffer): IBootSectorInfo | null {
export class FloppyDisk {
private readonly _buffer = new ArrayBuffer(0)
private _bootSector: IBootSectorInfo | null = null
constructor(buffer: ArrayBuffer) {
this._buffer = buffer
}
get bootSectorInfo() {
return (this._bootSector = this._bootSector ?? decodeBootSector(this._buffer))
}
}
function decodeBootSector(buffer: ArrayBuffer): IBootSectorInfo | null {
if (buffer.byteLength < 512) {
return null
}