1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-12-21 08:30:55 +00:00

Refactor code to pass image type in

This commit is contained in:
Peter Evans 2018-02-21 00:23:12 -06:00
parent 8706a81d1f
commit 61eb880f49
5 changed files with 52 additions and 53 deletions

View File

@ -3,9 +3,9 @@
#include "vm_segment.h"
extern int apple2_dec_dos(vm_segment *, vm_segment *);
extern int apple2_dec_dos(int, vm_segment *, vm_segment *);
extern int apple2_dec_nib(vm_segment *, vm_segment *);
extern int apple2_dec_sector(vm_segment *, vm_segment *, int, int);
extern int apple2_dec_track(vm_segment *, vm_segment *, int, int);
extern int apple2_dec_track(int, vm_segment *, vm_segment *, int, int);
#endif

View File

@ -193,7 +193,7 @@ apple2_dd_decode(apple2dd *drive)
case DD_DOS33:
case DD_PRODOS:
apple2_dec_dos(drive->image, drive->data);
apple2_dec_dos(drive->image_type, drive->image, drive->data);
break;
default:

View File

@ -7,6 +7,7 @@
#include <stdbool.h>
#include "apple2.dd.h"
#include "apple2.dec.h"
#include "apple2.enc.h"
#include "vm_segment.h"
@ -33,7 +34,7 @@ static vm_8bit conv6bit[] = {
* given segment.
*/
int
apple2_dec_dos(vm_segment *dest, vm_segment *src)
apple2_dec_dos(int sectype, vm_segment *dest, vm_segment *src)
{
int i, doff, tracklen;
@ -42,7 +43,7 @@ apple2_dec_dos(vm_segment *dest, vm_segment *src)
}
for (i = 0, doff = 0; i < ENC_NUM_TRACKS; i++) {
tracklen = apple2_dec_track(dest, src, doff, i);
tracklen = apple2_dec_track(sectype, dest, src, doff, i);
// Something went wrong...
if (tracklen != ENC_DTRACK) {
@ -80,18 +81,18 @@ apple2_dec_nib(vm_segment *dest, vm_segment *src)
* This should return ENC_DTRACK bytes; if not, something went wrong.
*/
int
apple2_dec_track(vm_segment *dest, vm_segment *src, int doff, int track)
apple2_dec_track(int sectype, vm_segment *dest, vm_segment *src, int doff, int track)
{
int soff = track * ENC_ETRACK;
int orig = doff;
int sect, sectlen;
int sect, sectlen, soff;
// Tracks have 48 bytes of filler... at least, as we build them
// (actual disk media may have more or less, it seems). Let's skip
// what we see.
soff += ENC_ETRACK_HEADER;
soff = (track * ENC_ETRACK) + ENC_ETRACK_HEADER;
for (sect = 0; sect < ENC_NUM_SECTORS; sect++) {
doff =
(track * ENC_DTRACK) +
(apple2_dd_sector_num(sectype, sect) * ENC_DSECTOR);
// This is going to be 256, for all intents and purposes
sectlen = apple2_dec_sector(dest, src, doff, soff + ENC_ESECTOR_HEADER);
@ -101,13 +102,7 @@ apple2_dec_track(vm_segment *dest, vm_segment *src, int doff, int track)
return 0;
}
doff += sectlen;
soff += ENC_ESECTOR + ENC_ESECTOR_HEADER;
}
// Something isn't right...
if (doff - orig != ENC_DTRACK) {
return 0;
soff += ENC_ESECTOR;
}
return ENC_DTRACK;
@ -171,7 +166,7 @@ apple2_dec_sector(vm_segment *dest, vm_segment *src, int doff, int soff)
// The footer_ok variable will be true if the ending byte markers we
// expect to see are actually there.
int footer = soff + 9 + 0x157;
int footer = soff + 3 + 0x157;
bool footer_ok =
vm_segment_get(src, footer) == 0xde &&
vm_segment_get(src, footer + 1) == 0xaa &&
@ -186,7 +181,7 @@ apple2_dec_sector(vm_segment *dest, vm_segment *src, int doff, int soff)
// Here we mean to convert the 6-and-2 encoded bytes back into its
// first intermediate form
for (i = 0; i < 0x157; i++) {
conv[i] = conv6bit[vm_segment_get(src, soff + i + 9) & 0x7f];
conv[i] = conv6bit[vm_segment_get(src, soff + i + 3) & 0x7f];
}
// Originally, we XOR'd each byte when encoding; so we need to do

View File

@ -38,30 +38,34 @@ static vm_8bit f_sector[] = {
* Same as above -- ripped from apple2.enc.c
*/
static vm_8bit f_enc_sector[] = {
0xd5, 0xaa, 0xad, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf5, 0xaf, 0x9a, 0xd3, 0xfd, 0xb6, 0xcb,
0xb5, 0xfa, 0xb5, 0xe6, 0xb9, 0xf3, 0xea, 0xe7, 0xd6, 0xdb, 0xad, 0xb9, 0xfe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b, 0xaf,
0xf2, 0xcb, 0xea, 0xf5, 0xf9, 0xce, 0x9a, 0xfc, 0xdc, 0xef, 0xbb, 0xeb, 0xfa, 0xde, 0xb3, 0xbb,
0xb3, 0xaf, 0xbe, 0xb9, 0xbc, 0x97, 0xad, 0xcd, 0xea, 0xba, 0x9b, 0xea, 0xfe, 0xe7, 0xf3, 0xb5,
0xd6, 0xad, 0xf9, 0xee, 0xea, 0xe6, 0xfd, 0xdb, 0x9b, 0xfd, 0xf4, 0x96, 0xdf, 0xdf, 0xde, 0xaa,
0xeb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
static vm_segment *seg;
@ -83,13 +87,13 @@ TestSuite(apple2_dec, .init = setup, .fini = teardown);
Test(apple2_dec, sector)
{
vm_segment *src, *dest;
int len;
src = vm_segment_create(1000);
dest = vm_segment_create(1000);
vm_segment_copy_buf(src, f_enc_sector, 0, 0, 382);
cr_assert_eq(apple2_dec_sector(dest, src, 0, 0), 256);
vm_segment_copy_buf(src, f_enc_sector, 0, 0, 396);
cr_assert_eq(apple2_dec_sector(dest, src, 0, ENC_ESECTOR_HEADER), 256);
for (int i = 0; i < 256; i++) {
cr_assert_eq(vm_segment_get(dest, i), f_sector[i]);
@ -111,8 +115,8 @@ Test(apple2_dec, track)
vm_segment_set(orig, i, 0xff);
}
apple2_enc_track(enc, orig, sectab, 0, 0);
apple2_dec_track(dec, enc, 0, 0);
apple2_enc_track(DD_DOS33, enc, orig, 0, 0);
apple2_dec_track(DD_DOS33, dec, enc, 0, 0);
for (i = 0; i < ENC_DTRACK; i++) {
cr_assert_eq(vm_segment_get(dec, i),
@ -128,10 +132,10 @@ Test(apple2_dec, dos)
int i;
vm_segment_fread(seg, fp, 0, _140K_);
enc = apple2_enc_dos(seg, sectab);
dec = vm_segment_create(1000000);
enc = apple2_enc_dos(DD_DOS33, seg);
dec = vm_segment_create(_140K_);
apple2_dec_dos(dec, enc);
cr_assert_eq(apple2_dec_dos(DD_DOS33, dec, enc), OK);
for (i = 0; i < seg->size; i++) {
cr_assert_eq(vm_segment_get(seg, i),

Binary file not shown.